<!DOCTYPE html>
<html>
<head>
    <include file="Public/head"/>

    <script type="text/javascript" src="__DATA__/static/js/common.js"></script>
    <!--<script type="text/javascript" src="__DATA__/static/js/user.js"></script>-->
    <script type="text/javascript" src="__JS__/jquery-2.1.0.min.js"></script>
    <script type="text/javascript" src="__JS__/md5.js"></script>
</head>
<body style="background:#fff;">
<div id="tbh5v0">



        <!--<script type="text/javascript" src="__DATA__/static/js/utils.js"></script>-->
        <script type="text/javascript">
            var bonus_sn_empty = "请输入您要添加的红包号码！";
            var bonus_sn_error = "您输入的红包号码格式不正确！";
            var email_empty = "请输入您的电子邮件地址！";
            var email_error = "您输入的电子邮件地址格式不正确！";
            var old_password_empty = "请输入您的原密码！";
            var new_password_empty = "请输入您的新密码！";
            var confirm_password_empty = "请输入您的确认密码！";
            var both_password_error = "您现两次输入的密码不一致！";
            var msg_blank = "不能为空";
            var no_select_question = "您没有完成密码提示问题的操作";
        </script>
        <header id="header">
            <div class="header_l header_return"><a class="ico_10" href="javascript:history.go(-1);"> 返回 </a></div>
            <h1> 个人资料 </h1>
        </header>

        <section class="wrap">
            <form name="formEdit" action="user.php" method="post" onSubmit="return userEdit()">
                <section class="order_box padd1 radius10" style="padding-top:0;padding-bottom:0;border-bottom:0;">
                    <div class="table_box table_box2">
                        <dl>
                            <dd class="dd1">用户名</dd>
                            <input id="username" name="username" data-name="username" type="text" placeholder="输入用户名"
                                   value="{$info.username}" class="dd2"/>
                        </dl>
                        <dl>
                            <dd class="dd1">电子邮箱</dd>
                            <input id="email" name="email" data-name="email" type="text" placeholder="输入电子邮箱"
                                   value="{$info.email}" class="dd2"/>
                        </dl>
                    </div>
                </section>
                <!-- <div class="blank3"></div> -->
            </form>
            <div style="background:#f0f0f0; height:10px;"></div>
            <form name="formPassword" action="{:U('Center/')}" method="post" onSubmit="return editPassword()"  style="background:#fff">
                <section class="order_box padd1 radius10" style="padding-top:0;padding-bottom:0;">
                    <div class="table_box table_box2">
                        <dl>
                            <dd class="dd1">原密码</dd>
                            <input id="old_password" placeholder="原密码" name="old_password" data-value="{:session('member.password')}" type="password" class="dd2"/>
                        </dl>
                        <dl>
                            <dd class="dd1">新密码</dd>
                            <input id="new_password" placeholder="新密码" name="new_password" type="password" class="dd2"/>
                        </dl>
                        <dl>
                            <dd class="dd1">确认密码</dd>
                            <input id="confirm_password" placeholder="确认密码" data-name="password" type="password" class="dd2"/>
                        </dl>

                    </div>
                </section><div style="width:94%; padding-left:3%;padding-right:3%;padding-bottom:5%;background:#fff">
                <div class="blank3"></div>
                
                <input name="act" type="hidden" value="act_edit_password"/>
                <input id="submit" type="button" class="c-btn3" value="修改密码"/>
                </div>
            </form>
        </section>


        <script>
            $(function(){
                $("#username").on("change", function () {
                    send(this);
                });
                $("#email").on("change", function () {
                    send(this);
                });
                $("#submit").on('click',function(){
                    check_password();
                });

                //修改密码
                function check_password(){
                    if ($("#old_password").val().length < 3){
                        alert('请输入原密码');
                        return;
                    }
                    if(hex_md5($("#old_password").val()) != $("#old_password").data("value")){
                        alert("原密码不正确");
                        return;
                    }
                    if ($("#new_password").val().length < 3){
                        alert('请输入新密码');
                        return;
                    }
                    if ($("#new_password").val() == $("#confirm_password").val() && $("#new_password").val().length >= 3) {
                        console.log("密码相同,执行密码修改");
                        console.log(hex_md5($("#confirm_password").val()));
                        send($("#confirm_password"));

                    }else{
                        alert("确认密码不一致");
                        return;
                    }
                }

                //ajax 保存
                function send(that) {
                    console.log(that);
                    console.log("修改的字段 name=" + $(that).data("name"));
                    //字段名称
                    var name = $(that).data("name");
                    //字段值
                    var value = $(that).val();
                    //验证
                    switch (name) {
                        case 'username':
                        case 'email':
                        case 'company':
                        case 'address':
                        case 'sex':
                        case 'password':
                        case 'comfirm_password':
                            var query = "name=" + name + "&value=" + value;
                            break;
                        default:
                            console.log("匹配失败");
                            //出错
                    }

                    console.log(query);

                    $.post(
                            "{:U('Center/ajax_info')}",
                            query,
                            function (res) {
                                console.log(res);
                                if (1 == res.code) {
                                    alert("修改成功");
                                    window.location.href = "__SELF__";
                                } else {
                                    alert("修改失败 " + res.msg);
                                }
                            }
                    );


                }
            });

        </script>

</div>
</body>
<script type="text/javascript">
    var msg_title_empty = "留言标题为空";
    var msg_content_empty = "留言内容为空";
    var msg_title_limit = "留言标题不能超过200个字";
</script>
</html>
